/*
 */
package ihmprojet.view;

import ihmprojet.view.onglets.TypeNotificationEnum;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTabbedPane;

/**
 *
 * @author thomas
 */
public class MenuHelp extends javax.swing.JPanel {

    private JTabbedPane tabpane;
    private FenetrePrincipale fenp;

    public MenuHelp(JTabbedPane tab, FenetrePrincipale fp) {
        initComponents();
        tabpane = tab;
        tabpane.add("Help", this);
        fenp = fp;
        AfficherMenuGlobal();
    }

    public void afficherTexteAide(TypeNotificationEnum typeNotif) {
        afficherAideSpec(typeNotif.getTitre());
        this.jTextPanHelp.setText(typeNotif.getMessage());
    }

    public void afficherAideSpec(String titre) {
        this.tabpane.setSelectedIndex(1);
        jTextPanHelp.setVisible(true);
        JlabelPlusPDF.setVisible(true);
        jScrollPane1.setVisible(true);
        
        jlLabelretourMenuGlobal.setVisible(true);
        jLabelCreerTache.setVisible(false);
        jLabelrelBin.setVisible(false);
        jLabelRelUnaire.setVisible(false);
        jLabelTitre.setText(titre);
    }

    public void AfficherMenuGlobal() {
        this.tabpane.setSelectedIndex(1);
        jTextPanHelp.setVisible(false);
        jScrollPane1.setVisible(false);
        
        jlLabelretourMenuGlobal.setVisible(false);
        jLabelCreerTache.setVisible(true);
        jLabelrelBin.setVisible(true);
        jLabelRelUnaire.setVisible(true);
        jLabelTitre.setText("Global menu ");
    }

    void afficherDocPDF() {
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            try {
                File f = new File("Manuel.pdf");
                try {
                    try {
                        java.awt.Desktop.getDesktop().open(f);
                    } catch (IOException ex) {
                        Logger.getLogger(MenuHelp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    fenp.changerLabelNotification(TypeNotificationEnum.HelpMenu);
                } catch (java.lang.IllegalArgumentException ex) {
                    System.err.println("Desktop not supported");
                    fenp.changerLabelNotification(TypeNotificationEnum.Manuel);
                }
            } catch (NullPointerException e) {
                fenp.changerLabelNotification(TypeNotificationEnum.ManuelNotFound);
            }
        } else {
            System.err.println("Desktop not supported");
            fenp.changerLabelNotification(TypeNotificationEnum.Manuel);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButton1 = new javax.swing.JRadioButton();
        jLabelTitre = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPanHelp = new javax.swing.JTextPane();
        jSeparator1 = new javax.swing.JSeparator();
        jLabelrelBin = new javax.swing.JLabel();
        jLabelRelUnaire = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabelCreerTache = new javax.swing.JLabel();
        jlLabelretourMenuGlobal = new javax.swing.JLabel();
        JlabelPlusPDF = new javax.swing.JLabel();

        jRadioButton1.setText("jRadioButton1");

        setBackground(new java.awt.Color(51, 51, 51));
        setForeground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(32767, 200));
        setPreferredSize(new java.awt.Dimension(248, 200));
        setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 10));

        jLabelTitre.setForeground(new java.awt.Color(255, 255, 255));
        jLabelTitre.setText("Titre");
        add(jLabelTitre);

        jScrollPane1.setMaximumSize(new java.awt.Dimension(150, 32767));
        jScrollPane1.setMinimumSize(new java.awt.Dimension(150, 22));
        jScrollPane1.setPreferredSize(new java.awt.Dimension(150, 150));

        jTextPanHelp.setFont(new java.awt.Font("DejaVu Sans", 0, 10)); // NOI18N
        jTextPanHelp.setText("Bienvenue dans le menu d'aide! Mais il n'y en a pas . dsl!");
        jTextPanHelp.setFocusable(false);
        jTextPanHelp.setMaximumSize(new java.awt.Dimension(200, 2147483647));
        jTextPanHelp.setMinimumSize(new java.awt.Dimension(150, 100));
        jTextPanHelp.setPreferredSize(new java.awt.Dimension(200, 100));
        jScrollPane1.setViewportView(jTextPanHelp);

        add(jScrollPane1);
        add(jSeparator1);

        jLabelrelBin.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
        jLabelrelBin.setForeground(new java.awt.Color(255, 255, 255));
        jLabelrelBin.setText("Binary relation");
        jLabelrelBin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelrelBinMouseClicked(evt);
            }
        });
        add(jLabelrelBin);

        jLabelRelUnaire.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
        jLabelRelUnaire.setForeground(new java.awt.Color(255, 255, 255));
        jLabelRelUnaire.setText("Unary relation");
        jLabelRelUnaire.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelRelUnaireMouseClicked(evt);
            }
        });
        add(jLabelRelUnaire);
        add(jSeparator2);

        jLabelCreerTache.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
        jLabelCreerTache.setForeground(new java.awt.Color(255, 255, 255));
        jLabelCreerTache.setText("How to create task");
        jLabelCreerTache.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelCreerTacheMouseClicked(evt);
            }
        });
        add(jLabelCreerTache);

        jlLabelretourMenuGlobal.setForeground(new java.awt.Color(255, 255, 255));
        jlLabelretourMenuGlobal.setText("> Back help menu");
        jlLabelretourMenuGlobal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jlLabelretourMenuGlobalMouseClicked(evt);
            }
        });
        add(jlLabelretourMenuGlobal);

        JlabelPlusPDF.setForeground(new java.awt.Color(255, 255, 255));
        JlabelPlusPDF.setText("More help >>PDF");
        JlabelPlusPDF.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JlabelPlusPDFMouseClicked(evt);
            }
        });
        add(JlabelPlusPDF);
    }// </editor-fold>//GEN-END:initComponents

    private void JlabelPlusPDFMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JlabelPlusPDFMouseClicked
        afficherDocPDF();
    }//GEN-LAST:event_JlabelPlusPDFMouseClicked

    private void jlLabelretourMenuGlobalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jlLabelretourMenuGlobalMouseClicked
        this.AfficherMenuGlobal();
    }//GEN-LAST:event_jlLabelretourMenuGlobalMouseClicked

    private void jLabelRelUnaireMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelRelUnaireMouseClicked
        afficherTexteAide(TypeNotificationEnum.HelpUnaire);
    }//GEN-LAST:event_jLabelRelUnaireMouseClicked

    private void jLabelrelBinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelrelBinMouseClicked
        afficherTexteAide(TypeNotificationEnum.HelpBinary);
    }//GEN-LAST:event_jLabelrelBinMouseClicked

    private void jLabelCreerTacheMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelCreerTacheMouseClicked
        afficherTexteAide(TypeNotificationEnum.HelpCreateTask);
    }//GEN-LAST:event_jLabelCreerTacheMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JlabelPlusPDF;
    private javax.swing.JLabel jLabelCreerTache;
    private javax.swing.JLabel jLabelRelUnaire;
    private javax.swing.JLabel jLabelTitre;
    private javax.swing.JLabel jLabelrelBin;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextPane jTextPanHelp;
    private javax.swing.JLabel jlLabelretourMenuGlobal;
    // End of variables declaration//GEN-END:variables
}
